/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Converter;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

/**
 *
 * @author Iron
 */
@FacesConverter("DateConverter")
public class DataConverter implements Converter{

    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        try {   
            
            Date nascimento = (Date)new SimpleDateFormat("dd/MM/yyyy").parse(value);
            return nascimento;
        } catch (ParseException ex) {
            System.out.println("Erro a converter Data!!");
            return null;
        }
    }

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
        try{
        Date data = (Date) value;
        SimpleDateFormat formato = new SimpleDateFormat("dd/MM/yyyy");  
        return formato.format(data);  
        }catch(Exception ex){
            System.out.println("Error ao converter Data");
            return null;
        }
    }
    
  	
    
}
